﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;



namespace syc.Admin
{
    public partial class 物料权限设置 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                string uid = Request.QueryString["uid"];
                if (string.IsNullOrEmpty(uid))
                {
                    Response.End();
                }
                else
                {
                    uid = uid.Replace("'", "''");
                }

                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;
                Cmd.CommandText = "select 姓名,产品权限,原料权限 from 操作员 where 工号='" + uid + "'";
                SqlDataReader Dr = Cmd.ExecuteReader();
                if (Dr.Read())
                {
                    this.XingMing.Text = (string)Dr["姓名"];
                    this.GongHao.Text = uid;
                    string qx = (string)Dr["产品权限"];
                    if (qx.IndexOf(",1,") > -1)
                    {
                        this.ChanPin1.Checked = true;
                    }
                    if (qx.IndexOf(",2,") > -1)
                    {
                        this.ChanPin2.Checked = true;
                    }
                    if (qx.IndexOf(",3,") > -1)
                    {
                        this.ChanPin3.Checked = true;
                    }
                    if (qx.IndexOf(",4,") > -1)
                    {
                        this.ChanPin4.Checked = true;
                    }
                    if (qx.IndexOf(",5,") > -1)
                    {
                        this.ChanPin4.Checked = true;
                    }
                    if (qx.IndexOf(",6,") > -1)
                    {
                        this.ChanPin4.Checked = true;
                    }
                    if (qx.IndexOf(",7,") > -1)
                    {
                        this.ChanPin4.Checked = true;
                    }

                    qx = (string)Dr["原料权限"];
                    if (qx.IndexOf(",1,") > -1)
                    {
                        this.YuanLiao1.Checked = true;
                    }
                    if (qx.IndexOf(",2,") > -1)
                    {
                        this.YuanLiao2.Checked = true;
                    }
                    if (qx.IndexOf(",3,") > -1)
                    {
                        this.YuanLiao3.Checked = true;
                    }
                    if (qx.IndexOf(",4,") > -1)
                    {
                        this.YuanLiao4.Checked = true;
                    }
                    if (qx.IndexOf(",5,") > -1)
                    {
                        this.YuanLiao5.Checked = true;
                    }
                    if (qx.IndexOf(",6,") > -1)
                    {
                        this.YuanLiao6.Checked = true;
                    }
                    if (qx.IndexOf(",7,") > -1)
                    {
                        this.YuanLiao7.Checked = true;
                    }
                    if (qx.IndexOf(",8,") > -1)
                    {
                        this.YuanLiao8.Checked = true;
                    }


                    if (qx.IndexOf(",101,") > -1)
                    {
                        this.YuanLiao101.Checked = true;
                    }
                    if (qx.IndexOf(",102,") > -1)
                    {
                        this.YuanLiao102.Checked = true;
                    }
                    if (qx.IndexOf(",103,") > -1)
                    {
                        this.YuanLiao103.Checked = true;
                    }
                    if (qx.IndexOf(",104,") > -1)
                    {
                        this.YuanLiao104.Checked = true;
                    }
                    if (qx.IndexOf(",105,") > -1)
                    {
                        this.YuanLiao105.Checked = true;
                    }
                    if (qx.IndexOf(",106,") > -1)
                    {
                        this.YuanLiao106.Checked = true;
                    }
                    if (qx.IndexOf(",107,") > -1)
                    {
                        this.YuanLiao107.Checked = true;
                    }

                }
                Dr.Close();
                Dr.Dispose();
                Cmd.Dispose();
                Conn.Close();
                Conn.Dispose();
            }
        }

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            string uid = Request.QueryString["uid"];
            if (string.IsNullOrEmpty(uid))
            {
                Response.End();
            }
            else
            {
                uid = uid.Replace("'", "''");
            }
            string qx1 = ",";
            string qx2 = ",";
            if (this.ChanPin1.Checked) qx1 += "1,";
            if (this.ChanPin2.Checked) qx1 += "2,";
            if (this.ChanPin3.Checked) qx1 += "3,";
            if (this.ChanPin4.Checked) qx1 += "4,";
            if (this.ChanPin5.Checked) qx1 += "5,";
            if (this.ChanPin6.Checked) qx1 += "6,";
            if (this.ChanPin7.Checked) qx1 += "7,";



            if (this.YuanLiao1.Checked) qx2 += "1,";
            if (this.YuanLiao2.Checked) qx2 += "2,";
            if (this.YuanLiao3.Checked) qx2 += "3,";
            if (this.YuanLiao4.Checked) qx2 += "4,";
            if (this.YuanLiao5.Checked) qx2 += "5,";
            if (this.YuanLiao6.Checked) qx2 += "6,";
            if (this.YuanLiao7.Checked) qx2 += "7,";
            if (this.YuanLiao8.Checked) qx2 += "8,";

            if (this.YuanLiao101.Checked) qx2 += "101,";
            if (this.YuanLiao102.Checked) qx2 += "102,";
            if (this.YuanLiao103.Checked) qx2 += "103,";
            if (this.YuanLiao104.Checked) qx2 += "104,";
            if (this.YuanLiao105.Checked) qx2 += "105,";
            if (this.YuanLiao106.Checked) qx2 += "106,";
            if (this.YuanLiao107.Checked) qx2 += "107,";


            SqlConnection Conn = new SqlConnection();
            Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
            Conn.Open();
            SqlCommand Cmd = new SqlCommand();
            Cmd.Connection = Conn;
            Cmd.CommandText = "update [操作员] set 产品权限='" + qx1 + "',原料权限='" + qx2 + "' where [工号]='" + uid + "'";

            Cmd.ExecuteNonQuery();
            Cmd.Dispose();
            Conn.Close();
            Conn.Dispose();
            this.Message.Text = "·保存成功";
        }
    }
}
